package com.baizhi.service.impl;

import com.baizhi.config.log.LogAnnotation;
import com.baizhi.entity.Admin;
import com.baizhi.mapper.AdminMapper;
import com.baizhi.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Slf4j
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Transactional
    @LogAnnotation(content = "管理员登录",type = "select")
    public boolean login(String username,String password) {
        Admin admin = adminMapper.selectByName(username);
        if(admin!=null&&admin.getPassword().equals(password)){
            return true;
        }
        return false;
    }

    @Transactional(readOnly = true)
    public Admin selectByName(String username) {
        Admin admin = adminMapper.selectByName(username);
        return admin;
    }

    @Override
    public List<Admin> selectAll() {
        List<Admin> admins = adminMapper.selectList(null);
        log.info(admins+"");
        return admins;
    }

    @Override
    public void deleteById(Integer id) {
        log.info(id+"");
        adminMapper.deleteById(id);
    }

    @Override
    public void update(Admin admin) {
        
    }

    @Override
    public void insert(Admin admin) {

    }
}
